/**
 * Copyright (c) 2013-2022 Nikita Koksharov
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.redisson.api;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;

/**
 * 基于Redis实现的可重入锁
 */
public interface RLock extends Lock, RLockAsync {

    /**
     * 获取锁名称
     */
    String getName();

    /**
     * 尝试获取锁，如果当前线程中断，将抛出InterruptedException异常
     * 该方法也可在获取锁之前将等待可中断超时时间，如果成功获取锁，则返回true，如果超时或当前线程中断，则返回false
     */
    void lockInterruptibly(long leaseTime, TimeUnit unit) throws InterruptedException;

    /**
     * 尝试加锁，可设置锁超时时间和锁过期时间
     */
    boolean tryLock(long waitTime, long leaseTime, TimeUnit unit) throws InterruptedException;

    /**
     * 上锁，并设置锁过期时间
     */
    void lock(long leaseTime, TimeUnit unit);

    /**
     * 强制解锁
     */
    boolean forceUnlock();

    /**
     * 检查锁是否被线程锁定
     */
    boolean isLocked();

    /**
     * 检查锁是否由具有定义的线程持有threadId
     */
    boolean isHeldByThread(long threadId);

    /**
     * 检查当前线程是否持有锁
     */
    boolean isHeldByCurrentThread();

    /**
     * 当前线程对此锁的持有次数
     */
    int getHoldCount();

    /**
     * 锁的剩余生存时间
     */
    long remainTimeToLive();

}
